@REM 添加版本信息

@echo off


SETLOCAL
set input_file=%~1

call %g_bat_dir_path%\readini.bat %g_config_file_path% version strPrefix strPrefix
call %g_bat_dir_path%\readini.bat %g_config_file_path% version addr start_addr
call %g_bat_dir_path%\readini.bat %g_config_file_path% version size size

@if not defined strPrefix (
	set strPrefix=
)

@if not defined start_addr (
	@echo Error: .ini file [version: addr] does not set param
	exit /B 1
)

@if not defined size (
	@echo Error: .ini file [version: size] does not set param
	exit /B 1
)


if %time:~0,2% leq 9 (set hour=0%time:~1,1%) else (set hour=%time:~0,2%)
set minute=%time:~3,2%

@REM 打包的时间格式为年月日时分 T2206111526
set strVerTime=T%date:~2,2%%date:~5,2%%date:~8,2%%hour%%minute%

@set strVersion=%strPrefix%%strVerTime%
@echo generate version: %strVersion%

call %g_bat_dir_path%\vstr_len.bat %strVersion% str_len

@if %str_len% geq %size% (
	@echo Error: %str_len% over %size%, error exit
	@exit /B 1
)

@REM git 记录信息的结束位置
@set /a end_addr=%start_addr%+%str_len%

set output_file=ver_%input_file%
set input_file_name=%input_file%.hex
set output_file_name=%output_file%.hex

%g_exe_dir_path%\srec_cat.exe -generate %start_addr% %end_addr% -repeat-string %strVersion% %g_obj_dir_path%\%input_file_name% -intel -exclude %start_addr% %end_addr% -o %g_obj_dir_path%\%output_file_name% -intel
@echo %input_file% add version info generate %output_file_name%

(endlocal
set %~2=%output_file%
set %~3=%strVersion%
)

ENDLOCAL
exit /B 0


